`
https://leetcode.cn/problems/binary-tree-tilt/
`

/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @return {number}
 */
var findTilt = function (root) {
  let res = 0

  const traverse = (root) => {
    if (root === null) return 0

    const leftSum = traverse(root.left)
    const rightSum = traverse(root.right)

    // 坡度累加到结果上
    res += Math.abs(leftSum - rightSum)

    // 返回该子树的结点之和
    return root.val + leftSum + rightSum
  }

  traverse(root)

  return res
};